package com.le.tester.imooc.masterJUC.threadlocal;

import com.le.tester.common.Const;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 描述：10个线程打印日期
 */
public class ThreadLocalNormalUsage01 {

    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < 30; i++) {
            int finalI = i;
            new Thread(() -> {
                String date = new ThreadLocalNormalUsage01().date(finalI);
                System.out.println("10 threadNum string date:" + date);
            }).start();
            Thread.sleep(100);
        }
    }

    public String date(int seconds) {
        //字符串日期格式转换,参数的单位是毫秒，从1970.01.01 00:00:00 GTM开始计时
        Date date = new Date(1000 * seconds);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(Const.STANDARD_FORMAT);
        return simpleDateFormat.format(date);
    }
}
